import React from 'react';
import {Select } from 'antd';
const Option = Select.Option;

class SCSelect extends React.Component {
    constructor(props) {
        super(props);
        // console.log('props',props)
        const value = props.initialValue || {};
        this.state = {
            currency: value.currency,
            options:[],
        };
    }


    componentDidMount() {
        //接口数据
        if(this.props.url){
            this.getStuGroup();
        }
        //js 自定义数据
        if(this.props.data){
            this.setState(Object.assign(this.state.options, {options: this.props.data}))
        }
    }

     getStuGroup = async() => {
        let response=await this.props.url();
        if(response&&response.data){
            if(this.props.transfromData){
                response.data=this.props.transfromData(response.data)
            }
            this.setState(Object.assign(this.state.options, {options: response.data || []}))
        }
    }
    
    render() {
        return (
                <Select
                    value={this.state.currency}
                    optionLabelProp="children" optionFilterProp="children"
                    allowClear={true}
                    placeholder={this.props.placeholder||'请选择'}
                    {...this.props}
                >
                    {
                        this.state.options.map((item,index) =>
                            {   
                                return <Option value={item.id} key={index}>{item.name}</Option>
                            }
                        )
                    }
                </Select>
        )
    }
}

export default SCSelect;